package com.ruoyi.web.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysPrizeEvent;
import com.ruoyi.system.service.ISysPrizeEventService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author HP
 * @Date 2021/2/26
 * @Description TODO
 */
@Api("奖品管理")
@RestController
@RequestMapping("/system/prizeevent")
@Slf4j
public class SysPrizeEventController {
    @Autowired
    private ISysPrizeEventService iSysPrizeEventService;
    @PostMapping("/saveSysPrizeEvent")
    public AjaxResult saveSysPrizeEvent(SysPrizeEvent sysPrizeEvent){
        try {
            System.out.println(sysPrizeEvent);
            iSysPrizeEventService.saveSysPrizeEvent(sysPrizeEvent);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @GetMapping("/querySysPrizeEvent")
    public AjaxResult querySysPrizeEvent(SysPrizeEvent sysPrizeEvent,Integer pageNum,Integer pageSize){
        List<SysPrizeEvent> sysPrizeEvents = iSysPrizeEventService.querySysPrizeEvent(sysPrizeEvent,pageNum,pageSize);
        PageInfo pageInfo = new PageInfo(sysPrizeEvents);
        PageHelper.startPage(pageNum,pageSize);
        return AjaxResult.success(pageInfo);
    }

    @DeleteMapping("/deleteSysPrizeEvent/{id}")
    public AjaxResult deleteSysPrizeEvent(@PathVariable int id){
        iSysPrizeEventService.deleteSysPrizeEvent(id);
        return AjaxResult.success();
    }

    @GetMapping("/queryById")
    public AjaxResult queryById(int id){
        SysPrizeEvent sysPrizeEvent = iSysPrizeEventService.queryById(id);
        return AjaxResult.success(sysPrizeEvent);
    }

    /**
     * 根据赛事ID查看已分配的赛事礼品列表
     * @param epid
     * @return
     */
    @GetMapping("/queryByEpid")
    public AjaxResult queryByEpid(int epid){
        List<SysPrizeEvent> list = iSysPrizeEventService.queryByEpid(epid);
        return AjaxResult.success(list);
    }

    @PutMapping("/updateSysPrizeEvent")
    public AjaxResult updateSysPrizeEvent(SysPrizeEvent sysPrizeEvent){
        iSysPrizeEventService.updateSysPrizeEvent(sysPrizeEvent);
        return AjaxResult.success();
    }
}
